#include "ros/ros.h"
#include "std_msgs/String.h" //普通文本类型的消息
#include <sstream>
#include "std_msgs/Bool.h"

bool trigger_flight = false; // 是否触发飞行的标志位

// 回调函数：更新 trigger_flight 状态
void triggerCallback(const std_msgs::Bool::ConstPtr& msg)
{
    trigger_flight = msg->data;
}

int main(int argc, char *argv[])
{
    ros::init(argc, argv, "pub_trigger");
    ros::NodeHandle nh;

    // 发布器
    ros::Publisher pub = nh.advertise<std_msgs::String>("/nlink_linktrack_data_transmission", 10);
    // 订阅器
    ros::Subscriber sub = nh.subscribe("/trigger_flight", 10, triggerCallback);

    std_msgs::String msg;
    msg.data = "1";

    ros::Rate rate(1); // 1 Hz

    while (ros::ok())
    {
        ros::spinOnce(); // 处理回调

        if (trigger_flight)
        {
            pub.publish(msg);
        }

        rate.sleep();
    }

return 0;
}
